package com.toogu.mazhangmen;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;

import com.lib.EFUN_ATTR;
import com.lib.FunSDK;
import com.lib.IFunSDKResult;
import com.lib.MsgContent;
import com.lib.SDKCONST;
import com.lib.sdk.bean.StringUtils;
import com.manager.XMFunSDKManager;
import com.manager.account.AccountManager;
import com.manager.account.BaseAccountManager;
import com.tencent.bugly.crashreport.CrashReport;
import com.utils.FileUtils;
import com.utils.PathUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class MyApplication extends Application{

    public static Context context;
    private XMFunSDKManager xmFunSDKManager;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        Context context = getApplicationContext();
//// 获取当前包名
//        String packageName = context.getPackageName();
//// 获取当前进程名
//        String processName = getProcessName(android.os.Process.myPid());
//// 设置是否为上报进程
//        CrashReport.UserStrategy strategy = new CrashReport.UserStrategy(context);
//        strategy.setUploadProcess(processName == null || processName.equals(packageName));
//// 初始化Bugly
//        CrashReport.initCrashReport(context, "7445be1941", false, strategy);

        xmFunSDKManager = XMFunSDKManager.getInstance();
        xmFunSDKManager.initXMCloudPlatform(this);
        //初始化 logcat上的日志，可以通过SDK_LOG过滤
        xmFunSDKManager.initLog();
        Log.d("Application", "onCreate: " + "初始化成功");
        FunSDK.SetFunIntAttr(EFUN_ATTR.SUP_RPS_VIDEO_DEFAULT, SDKCONST.Switch.Open);

        //FunSDK 本地登录
        String localPath = Environment.getExternalStorageDirectory() + "";//手机本地路径

//        本地登录
        AccountManager.getInstance().localLogin(localPath, new BaseAccountManager.OnAccountManagerListener() {
            @Override
            public void onSuccess(int msgId) {
            }

            @Override
            public void onFailed(int msgId, int errorId) {
            }

            @Override
            public void onFunSDKResult(Message msg, MsgContent ex) {
            }
        });
    }


    public static Context getContext() {
        return context;
    }

    private static String getProcessName(int pid) {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline"));
            String processName = reader.readLine();
            if (!TextUtils.isEmpty(processName)) {
                processName = processName.trim();
            }
            return processName;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException exception) {
                exception.printStackTrace();
            }
        }
        return null;
    }

}
